package com.aigis.big4.tmp.javase.thread;

import java.util.Date;

public final class Planet {
    private final double fMass;
    private final String fName;
    private final Date  fDateOfDiscovery;

    public Planet(double fMass, String fName, Date aDateOfDiscovery) {
        this.fMass = fMass;
        this.fName = fName;
        this.fDateOfDiscovery = new Date(aDateOfDiscovery.getTime());
    }

    public double getfMass() {
        return fMass;
    }

    public String getfName() {
        return fName;
    }
    //返回一个可变对象的一个保护性拷贝.调用者可以任意改变返回的Date对象,但是不会
    //影响类的内部.为什么? 因为它们没有fDate的一个引用. 更准确的说, 它们
    //使用的是和fDate有着相同数据的另一个Date对象
    public Date getfDateOfDiscovery() {
        return new Date(fDateOfDiscovery.getTime());
    }

    public static void main(String[] args) {
        Planet planet = new Planet(1.0D, "earth", new Date());
        System.out.println("the initial value of fDateOfDiscovery of internal class : " + planet.fDateOfDiscovery.getTime());
        Date date = planet.getfDateOfDiscovery();
        date.setTime(111111111L);
        System.out.println("the value of fDateOfDiscovery of internal class : " + planet.fDateOfDiscovery.getTime());
        System.out.println("the value of date after change its value : " + date.getTime());
    }
}
